package com.gongren.project.mq.receiver;

import com.alibaba.dubbo.config.annotation.Reference;
import com.gongren.project.odd.job.rpc.api.service.bill.IBillCallBackRpcService;
import com.gongren.project.orange.rpc.api.service.account.IOrangeCallPayRpcService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * Created by zhangjinxia on 2017/8/22.
 */
@Component
public class MqReceiver {

    private static Logger logger = LoggerFactory.getLogger(MqReceiver.class);

    private static Logger errorLogger = LoggerFactory.getLogger("gongrenMqErrorLogger");

    @Reference
    private IBillCallBackRpcService billCallBackRpcService;

    @Reference
    private IOrangeCallPayRpcService orangeCallPayRpcService;

    @RabbitListener(queues = "billAndOrangeCallback")
    public void billAndOrangeCallback(String businessNum) {
        logger.info(String.format("receive billAndOrangeCallback businessNum: %s", businessNum));
        try {
            billCallBackRpcService.updateBillStatus(businessNum);
            orangeCallPayRpcService.updateTradeStatus(businessNum);
        }catch (Exception e){
            errorLogger.error(String.format("receive billAndOrangeCallback businessNum: %s", businessNum));
            errorLogger.error("billAndOrangeCallback error:",e);
        }

    }
}
